#ifndef _AME_CLIENT_H_
#define _AME_CLIENT_H_

struct world_char;

struct client {
	struct sockaddr_in *s;
	struct {
		unsigned short readable : 1;
		unsigned short writable : 1;
	} net;
	unsigned userid: 16;
	unsigned logged: 1;
	unsigned fd: 16;

	unsigned map: 8;
	unsigned packetlen : 16;
	unsigned packetlife: 8;
	unsigned packetnum : 8;

	struct buffer *rbuffer;
	struct buffer *wbuffer;

	struct world_char *achar;
	struct world_cell *cell;
	struct chain_node *world_node;
	struct chain_node *global_hook;
	unsigned last_packet: 6; // Time we last received something from him/her.
	char name[16];
	unsigned eof: 1;
};

/* client.c */
struct client *client_init(int);
struct client *client_fromCharId(unsigned short);
int client_login(struct client *);
int client_enterMap(struct client *me, int map_id, int x, int y);
void client_leaveMap(struct client *);
int client_write(struct client *);
void client_shut(struct client *);
int client_parseRequest(struct client *);
int client_getRequest(struct client *);
int client_do(struct client *);
int client_pushMove(struct client *me,int x, int y);
void client_charShut(struct client *me);
inline void client_chats(struct client *me);

inline unsigned int READU8(struct client *me);
inline unsigned int READU16(struct client *me);
inline unsigned int READU32(struct client *me);
inline signed int READS16(struct client *me);
inline signed int READS32(struct client *me);
inline float READF32(struct client *me);

inline void PUTU8(struct client *me, int value);
inline void PUTU16(struct client *me, int value);

#endif
